package com.hunlian.makelove.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.NumberPicker;

import com.hunlian.makelove.R;

public class IncomeSelectorDialog extends Dialog {
	private Context mContext;
	private IncomeSelectorDialog dialog;
	private Handler mHandler;
	private NumberPicker mNpNum;
	private Button mBtnCancel,mBtnSure;
	private String[] mTimeUnitArray;
	public static final int Income_VALUE = 10002;
	public IncomeSelectorDialog(Context context) {
		super(context);
		mContext = context;
		dialog = this;
	}

	public IncomeSelectorDialog(Context context, int theme,
								Handler handler, String[] eduArray) {
		super(context, theme);
		mContext = context;
		dialog = this;
		mHandler = handler;
		mTimeUnitArray = eduArray;
	}
	
	private void setListener(){
		mBtnCancel.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				dialog.dismiss();
			}

		});
		
		mBtnSure.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String unite = mTimeUnitArray[mNpNum.getValue()];
				//Toast.makeText(mContext, num+value, 0).show();
				Message msg = new Message();
				Bundle b = new Bundle();
				b.putString("income", mTimeUnitArray[mNpNum.getValue()]);
				msg.setData(b);
				msg.what = Income_VALUE;
				if(mHandler!=null){
					mHandler.sendMessage(msg);
				}
				dialog.dismiss();

			}

		});
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.dialog_education_selector);
		
		mNpNum = (NumberPicker) this.findViewById(R.id.np);
		mBtnCancel = (Button) this.findViewById(R.id.btn_cancel);
		mBtnSure = (Button) this.findViewById(R.id.btn_sure);

		//mNpNum.setOnValueChangedListener(this);
		mNpNum.setDisplayedValues(mTimeUnitArray);
		mNpNum.setMinValue(0);
		mNpNum.setMaxValue(mTimeUnitArray.length - 1);
		mNpNum.setValue(1);

		setListener();

		//在使用的过程中，用户点击数字会弹出键盘，有时候会造成布局被挤压不好看，也有其他的需求
		mNpNum.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
	}
}
